package view;

import controller.CalcadoController;
import controller.CalcadosFiltradosController;
import controller.CategoriaController;
import controller.CorController;
import controller.FornecedorController;
import controller.NumeracaoController;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.RowFilter;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableRowSorter;
import model.CalcadoMODEL;
import model.CalcadosFiltradosMODEL;
import model.CategoriaMODEL;
import model.CorMODEL;
import model.FornecedorMODEL;
import model.ItensExperimentadosMODEL;
import model.NumeracaoMODEL;
import table.CellRenderer;
import table.TooltipCellRender;
import table.calcadosFiltrados.CalcadosFiltradosTable;


/**
 *
 * @author Welisson
 */
public class Consultas extends javax.swing.JDialog {
    private CalcadoController objCalcado = new CalcadoController();
    private List<CalcadoMODEL> listCalcado = new ArrayList<CalcadoMODEL>();

    private FornecedorController objFornecedor = new FornecedorController();
    private List<FornecedorMODEL> listMarcas = new ArrayList<FornecedorMODEL>();

    private CategoriaController objCategoria = new CategoriaController();
    private List<CategoriaMODEL> listCategorias = new ArrayList<CategoriaMODEL>();

    private NumeracaoController objNumeracao = new NumeracaoController();
    private List<NumeracaoMODEL> listNumeracoes = new ArrayList<NumeracaoMODEL>();

    private CorController objCor = new CorController();
    private List<CorMODEL> listCores = new ArrayList<CorMODEL>();

    private List<CalcadosFiltradosMODEL> dadosListados;
    private List<CalcadosFiltradosMODEL> dadosListados2;

    private JTable tblCalcados;
    private CalcadosFiltradosTable tableModel;
    private JScrollPane scrollPane;
    
    private JTable tblCalcados2;
    private CalcadosFiltradosTable tableModel2;
    private JScrollPane scrollPane2;

    private TableRowSorter sorter;
    /**
     * Creates new form Consultas
     */
    public Consultas(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setResizable(false);
        this.setLocationRelativeTo(null);
        
        dadosListados2 = new ArrayList<>();
        
        preencherCombos();
        montaTabela();
        filtroDaTabela();
        
        montaTabela2();
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jBGGenero = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jCMarca = new javax.swing.JComboBox();
        jCNome = new javax.swing.JComboBox();
        jCCategoria = new javax.swing.JComboBox();
        jCNumeracao = new javax.swing.JComboBox();
        jCCor = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jRBMasc = new javax.swing.JRadioButton();
        jRBFem = new javax.swing.JRadioButton();
        jPanel3 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Filtros"));

        jCMarca.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCMarcaItemStateChanged(evt);
            }
        });

        jCNome.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCNomeItemStateChanged(evt);
            }
        });

        jCCategoria.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCCategoriaItemStateChanged(evt);
            }
        });

        jCNumeracao.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCNumeracaoItemStateChanged(evt);
            }
        });

        jCCor.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCCorItemStateChanged(evt);
            }
        });

        jLabel1.setText("Modelo:");

        jLabel2.setText("Gênero:");

        jLabel3.setText("Marca:");

        jLabel4.setText("Categoria:");

        jLabel5.setText("Numeração:");

        jLabel6.setText("Cor:");

        jBGGenero.add(jRBMasc);
        jRBMasc.setSelected(true);
        jRBMasc.setText("Masc.");
        jRBMasc.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRBMascMouseClicked(evt);
            }
        });

        jBGGenero.add(jRBFem);
        jRBFem.setText("Fem.");
        jRBFem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRBFemMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCMarca, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRBMasc, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRBFem, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCNome, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCNumeracao, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCCor, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jCMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jCNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jRBMasc)
                            .addComponent(jRBFem))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCNumeracao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCCor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Resultados"));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 279, Short.MAX_VALUE)
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Pesquisar"));

        jTPesquisa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTPesquisaKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(440, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(12, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Controles"));

        jBAdicionar.setText("Adicionar");
        jBAdicionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAdicionarActionPerformed(evt);
            }
        });

        jBRemover.setText("Remover");
        jBRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBRemoverActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jBAdicionar, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jBRemover, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jBAdicionar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBRemover)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Experimentar"));

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 221, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jMenuBar1.setBackground(new java.awt.Color(51, 51, 51));

        jMSalvar.setForeground(new java.awt.Color(255, 255, 255));
        jMSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/Save.png"))); // NOI18N
        jMSalvar.setText("Gravar");
        jMSalvar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jMSalvar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMSalvarMouseClicked(evt);
            }
        });
        jMenuBar1.add(jMSalvar);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jCMarcaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCMarcaItemStateChanged

        if(jCMarca.getSelectedIndex() >= 1){
            preencheComboNome(listMarcas.get(jCMarca.getSelectedIndex()-1).getId());
        }

        filtraProdutos();
    }//GEN-LAST:event_jCMarcaItemStateChanged

    private void jCNomeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCNomeItemStateChanged
        filtraProdutos();
    }//GEN-LAST:event_jCNomeItemStateChanged

    private void jCCategoriaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCCategoriaItemStateChanged
        filtraProdutos();
    }//GEN-LAST:event_jCCategoriaItemStateChanged

    private void jCNumeracaoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCNumeracaoItemStateChanged
        filtraProdutos();
    }//GEN-LAST:event_jCNumeracaoItemStateChanged

    private void jCCorItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCCorItemStateChanged
        filtraProdutos();
    }//GEN-LAST:event_jCCorItemStateChanged

    private void jRBMascMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRBMascMouseClicked
        filtraProdutos();
    }//GEN-LAST:event_jRBMascMouseClicked

    private void jRBFemMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRBFemMouseClicked
        filtraProdutos();
    }//GEN-LAST:event_jRBFemMouseClicked

    private void jTPesquisaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTPesquisaKeyReleased
        String pesq = jTPesquisa.getText();
        
        if(pesq.trim().equals("")){
            sorter.setRowFilter(null);
        }else{
            System.out.println(pesq);
            sorter.setRowFilter(RowFilter.regexFilter(pesq));
        }

    }//GEN-LAST:event_jTPesquisaKeyReleased

    private void jBAdicionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAdicionarActionPerformed
        int[] selecionados = tblCalcados.getSelectedRows();
        
        for(int i = 0; i < selecionados.length; i++){
            
            boolean existe = false;
            for(CalcadosFiltradosMODEL c : dadosListados2){
                if(dadosListados.get(selecionados[i]).getCalcado()==c.getCalcado()
                        && dadosListados.get(selecionados[i]).getGenero().equals(c.getGenero())
                        && dadosListados.get(selecionados[i]).getCategoria().equals(c.getCategoria())
                        && dadosListados.get(selecionados[i]).getCor().equals(c.getCor())
                        && dadosListados.get(selecionados[i]).getDe()==c.getDe()
                        && dadosListados.get(selecionados[i]).getAte()==c.getAte()
                ){
                    existe = true;
                }
            }
            if(!existe){
                tableModel2.addDado(dadosListados.get(selecionados[i]));
            }
        }
        
    }//GEN-LAST:event_jBAdicionarActionPerformed

    private void jBRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBRemoverActionPerformed
        int[] selecionados = tblCalcados2.getSelectedRows();
        
        for(int i = selecionados.length-1; i >= 0; i--){
            System.out.println(selecionados[i]);
            tableModel2.removeDado(selecionados[i]);
            
        }
    }//GEN-LAST:event_jBRemoverActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAdicionar;
    private javax.swing.ButtonGroup jBGGenero;
    private javax.swing.JButton jBRemover;
    private javax.swing.JComboBox jCCategoria;
    private javax.swing.JComboBox jCCor;
    private javax.swing.JComboBox jCMarca;
    private javax.swing.JComboBox jCNome;
    private javax.swing.JComboBox jCNumeracao;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JMenu jMSalvar;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JRadioButton jRBFem;
    private javax.swing.JRadioButton jRBMasc;
    private javax.swing.JTextField jTPesquisa;
    // End of variables declaration//GEN-END:variables

    private void preencherCombos(){

        preencheListas();
        preencheComboMarca();
//        preencheComboNome();
        preencheComboCategoria();
        preencheComboNumeracao();
        preencheComboCor();

    }

    private void preencheListas(){
        listCalcado = objCalcado.listar();
        listMarcas = objFornecedor.listaFornecedores();
        listCategorias = objCategoria.listar();
        listNumeracoes = objNumeracao.listar();
        listCores = objCor.listar();
    }

    private void preencheComboMarca(){
        jCMarca.removeAllItems();
        jCMarca.addItem("Selecione");
        for(FornecedorMODEL marcas : listMarcas){

            jCMarca.addItem(marcas.getRazaoSocial());

        }
    }

    private void preencheComboNome(int marca){

        listCalcado = objCalcado.listarPorMarca(marca);
        jCNome.removeAllItems();
        jCNome.addItem("Selecione");
        for(CalcadoMODEL calcado : listCalcado){

            jCNome.addItem(calcado.getNome());

        }
    }

    private void preencheComboCategoria(){
        jCCategoria.removeAllItems();
        jCCategoria.addItem("Selecione");
        for(CategoriaMODEL categorias : listCategorias){

            jCCategoria.addItem(categorias.getCategoria());

        }
    }

    private void preencheComboNumeracao(){
        jCNumeracao.removeAllItems();
        jCNumeracao.addItem("Selecione");
        for(NumeracaoMODEL numero : listNumeracoes){

            jCNumeracao.addItem("De: "+numero.getDe()+" Até: "+numero.getAte());

        }
    }

    private void preencheComboCor(){
        jCCor.removeAllItems();
        jCCor.addItem("Selecione");
        for(CorMODEL cor : listCores){

            jCCor.addItem(cor.getCor());

        }
    }

    private void filtraProdutos(){
        int marca = 0;
        String modelo = "";
        String gen = "";
        int categoria = 0;
        int numeracao = 0;
        int cor = 0;
        List<Object> dados = new ArrayList<Object>();


        String query = "SELECT DISTINCT calcado.cal_id, calcado.cal_nome, calcado.cal_genero, cal_valor, cat_categoria, "
                + "cal_qtd, cor_cores, num_de, num_ate "
                + "FROM "
                + "calcado, categoria, atributos, numeracao, cores, fornecedor "
                + "WHERE "
                + "calcado.cal_id = atributos.cal_id AND "
                + "atributos.cor_id = cores.cor_id AND "
                + "atributos.num_id = numeracao.num_id AND "
                + "calcado.cat_id = categoria.cat_id ";

        if(jCNome.getSelectedIndex() >= 1){
            modelo = (String) jCNome.getSelectedItem();
            query += " AND calcado.cal_nome = ?";
            dados.add(modelo);
        }

        if(jRBMasc.isSelected()){
            gen = "Masculino";
        }else{
            gen = "Feminino";
        }
        query += " AND calcado.cal_genero = ?";
        dados.add(gen);

        if(jCCategoria.getSelectedIndex() >= 1){
            categoria = listCategorias.get(jCCategoria.getSelectedIndex()-1).getId();
            query += " AND categoria.cat_id = ?";
            dados.add(categoria);
        }
        if(jCNumeracao.getSelectedIndex() >= 1){
            numeracao = listNumeracoes.get(jCNumeracao.getSelectedIndex()-1).getId();
            query += " AND numeracao.num_id = ?";
            dados.add(numeracao);
        }
        if(jCCor.getSelectedIndex() >= 1){
            cor = listCores.get(jCCor.getSelectedIndex()-1).getId();
            query += " AND cores.cor_id = ?";
            dados.add(cor);
        }

        if(jCMarca.getSelectedIndex() >= 1){
            marca = listMarcas.get(jCMarca.getSelectedIndex()-1).getId();
            query += " AND calcado.for_id = ?";
            dados.add(marca);
        }
        query += " ORDER BY cal_id";

//        System.out.println(query);
//        System.exit(0);


        dadosListados = new CalcadoController().filtrar(query, dados);
//        System.out.println("Total ----> "+ dadosListados.size());


        if(tableModel != null){
            atualizaTabela();
        }
    }


    //METODOS DA TABELA
    private void atualizaTabela(){
        tableModel.removeAll();
        for(CalcadosFiltradosMODEL calcado : dadosListados){
            tableModel.addDado(calcado);
        }
    }

    private void montaTabela() {

//        System.out.println(dadosListados.size());
        jPanel3.add(getTblCores());
        scrollPane.setBounds(5, 20, jPanel3.getWidth() - 10, jPanel3.getHeight() - 25);
    }

    private JScrollPane getTblCores() {
        if (tblCalcados == null) {
            tblCalcados = new JTable();
            // permite selecionar apenas uma linha de cada vez
//            tblCalcados.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            tblCalcados.setDefaultRenderer(String.class, new CellRenderer());

            tblCalcados.addMouseListener(new MouseAdapter() {

                @Override
                public void mouseClicked(MouseEvent me) {
                    //        System.out.println(linhaSelecionada);
                    if ((me.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
                        if (tblCalcados.isEnabled()) {

//                            if (status == VISUALIZAR) {
//                                statusTela(SELECIONAR);
//
//                            }
                        }
                    } else if ((me.getModifiers() & MouseEvent.BUTTON2_MASK) != 0) {
                        JOptionPane.showMessageDialog(null, "Isso não é algo Legal!");
                    } else if ((me.getModifiers() & MouseEvent.BUTTON3_MASK) != 0) {
                        JPopupMenu menu = new JPopupMenu();
                        JMenuItem cliqueme = new JMenuItem("Copiar");
                        int col = tblCalcados.columnAtPoint(me.getPoint());
                        int row = tblCalcados.rowAtPoint(me.getPoint());
                        cliqueme.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent ae) {
                                copyClipboard(String.valueOf(tableModel.get(row, col)));
                            }
                        });

                        menu.add(cliqueme);

                        menu.show(tblCalcados, me.getX(), me.getY());
                    }
                }

            });
            tblCalcados.setModel(getTableModel());
            defineRenderers();
            scrollPane = new JScrollPane(tblCalcados);
        }
        return scrollPane;
    }

    private CalcadosFiltradosTable getTableModel() {
        if (tableModel == null) {
            tableModel = new CalcadosFiltradosTable(dadosListados);

        }
        return tableModel;
    }

    private void defineRenderers() {
//        DefaultTableCellRenderer rendererCentro = new DefaultTableCellRenderer();
//        rendererCentro.setHorizontalAlignment(SwingConstants.CENTER);
//        DefaultTableCellRenderer rendererDireita = new DefaultTableCellRenderer();
//        rendererDireita.setHorizontalAlignment(SwingConstants.RIGHT);
//        DefaultTableCellRenderer rendererEsquerda = new DefaultTableCellRenderer();
//        rendererEsquerda.setHorizontalAlignment(SwingConstants.LEFT);

        JTableHeader header = tblCalcados.getTableHeader();
        header.setPreferredSize(new Dimension(0, 35));
        TableColumnModel modeloDaColuna = tblCalcados.getColumnModel();
        int[] tam = {100, 70,50,70,70,70,50,50};

        for (int i = 0; i < tableModel.getColumnCount(); i++) {
            modeloDaColuna.getColumn(i).setMaxWidth(tam[i]);
            modeloDaColuna.getColumn(i).setCellRenderer(new TooltipCellRender());

        }

    }

    //METODOS DA TABELA 2
    private void atualizaTabela2(){
        tableModel.removeAll();
        for(CalcadosFiltradosMODEL calcado2 : dadosListados2){
            tableModel.addDado(calcado2);
        }
    }

    private void montaTabela2() {

//        System.out.println(dadosListados.size());
        jPanel6.add(getTblCores2());
        scrollPane2.setBounds(5, 20, jPanel6.getWidth() - 10, jPanel6.getHeight() - 25);
    }

    private JScrollPane getTblCores2() {
        if (tblCalcados2 == null) {
            tblCalcados2 = new JTable();
            // permite selecionar apenas uma linha de cada vez
//            tblCalcados2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            tblCalcados2.setDefaultRenderer(String.class, new CellRenderer());

            tblCalcados2.addMouseListener(new MouseAdapter() {

                @Override
                public void mouseClicked(MouseEvent me) {
                    //        System.out.println(linhaSelecionada);
                    if ((me.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
                        if (tblCalcados2.isEnabled()) {

//                            if (status == VISUALIZAR) {
//                                statusTela(SELECIONAR);
//
//                            }
                        }
                    } else if ((me.getModifiers() & MouseEvent.BUTTON2_MASK) != 0) {
                        JOptionPane.showMessageDialog(null, "Isso não é algo Legal!");
                    } else if ((me.getModifiers() & MouseEvent.BUTTON3_MASK) != 0) {
                        JPopupMenu menu = new JPopupMenu();
                        JMenuItem cliqueme = new JMenuItem("Copiar");
                        int col = tblCalcados2.columnAtPoint(me.getPoint());
                        int row = tblCalcados2.rowAtPoint(me.getPoint());
                        cliqueme.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent ae) {
                                copyClipboard(String.valueOf(tableModel2.get(row, col)));
                            }
                        });

                        menu.add(cliqueme);

                        menu.show(tblCalcados2, me.getX(), me.getY());
                    }
                }

            });
            tblCalcados2.setModel(getTableModel2());
            defineRenderers2();
            scrollPane2 = new JScrollPane(tblCalcados2);
        }
        return scrollPane2;
    }

    private CalcadosFiltradosTable getTableModel2() {
        if (tableModel2 == null) {
            tableModel2 = new CalcadosFiltradosTable(dadosListados2);
        }
        return tableModel2;
    }

    private void defineRenderers2() {
//        DefaultTableCellRenderer rendererCentro = new DefaultTableCellRenderer();
//        rendererCentro.setHorizontalAlignment(SwingConstants.CENTER);
//        DefaultTableCellRenderer rendererDireita = new DefaultTableCellRenderer();
//        rendererDireita.setHorizontalAlignment(SwingConstants.RIGHT);
//        DefaultTableCellRenderer rendererEsquerda = new DefaultTableCellRenderer();
//        rendererEsquerda.setHorizontalAlignment(SwingConstants.LEFT);

        JTableHeader header = tblCalcados2.getTableHeader();
        header.setPreferredSize(new Dimension(0, 35));
        TableColumnModel modeloDaColuna = tblCalcados2.getColumnModel();
        int[] tam = {100, 70,50,70,70,70,50,50};

        for (int i = 0; i < tableModel2.getColumnCount(); i++) {
            modeloDaColuna.getColumn(i).setMaxWidth(tam[i]);
            modeloDaColuna.getColumn(i).setCellRenderer(new TooltipCellRender());

        }

    }
    
    
    private void copyClipboard(String texto) {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        StringSelection selection = new StringSelection(texto);
        clipboard.setContents(selection, null);
    }

    private void filtroDaTabela() {
        sorter = new TableRowSorter<CalcadosFiltradosTable>(tableModel);
        tblCalcados.setRowSorter(sorter);
    }
    
    
}
